// var io = require('socket.io-client');
// var constant = require('../../core/config/constant.config');

loginController.$inject = ['$scope','loginService','$location','$rootScope'];
function loginController($scope,loginService,$location,$rootScope) {
    // var vm = this;
    $scope.login = function () {
        console.log($scope.user);
        loginService.login($scope.user)
            .then(function(res){
                console.log(res.data);
                var rs = res.data;
                if(!rs.result){
                    $scope.errMsg = rs.errMsg;
                }else {
                    $scope.errMsg = '';
                    sessionStorage.user = JSON.stringify(rs.data);

                    //socket
                    // var socketConfig = {
                    //     path:constant.CONTEXT_PATH+'socketio'
                    // }
                    // var socket = io.connect(location.origin,socketConfig);
                    // sessionStorage.setItem('socket',socket);

                    console.log('user login success: '+sessionStorage.user);
                    $location.path('/acm/home');
                }
            });
    }
}

module.exports = loginController;